<template>
  <div class="recommend">
    <p class="housing">为您推荐的精品房源</p>
    <p class="excellent">推荐精品房源</p>
    <div>
      <div class="house_list">
        <div
          class="list"
          v-for="(item, index) in allHouse"
          :key="index"
          @click="onDetails(item.id)"
        >
          <div class="price">
            <img :src="item.img[0]" alt class="home_img" />
            <p
              class="soon"
              :class="[item.sellStage === '即将拍卖' ? 'soonGreen' : 'soonRed']"
            >{{ item.sellStage }}</p>
            <img
              :src="[
                item.ynFollow != 1
                  ? require(`@/assets/img/wdgzb_2.png`)
                  : require(`@/assets/img/ygz_2.png`)
              ]"
              alt
              class="heart"
              @click="Onfollow(item, index)"
            />
            <p class="home" v-if="item.houseStageName">{{ item.houseStageName }}</p>
            <p class="time" v-if="item.startSaleTimeStr">开拍时间：{{ item.startSaleTimeStr }}</p>
            <p class="time" v-else>开拍时间待定</p>
          </div>

          <div>
            <p class="list_title">{{ item.title }}</p>
            <p>
              <span class="hall">{{ item.bedRoomCount }}室{{ item.visitorRoomCount }}厅</span>
              <span class="centare" v-if=" item.coveredArea">{{ item.coveredArea }}㎡</span>
              <span class="orientation" v-if="item.directionName">朝{{ item.directionName }}</span>
            </p>
            <p class="price">
              市场价：
              <span v-if=" item.marketSalePrice">{{ item.marketSalePrice }}</span>
              <span v-else>--</span>万
            </p>
            <div class="startPrice">
              <p class="start">
                起拍价：
                <span v-if="item.startSalePrice">{{ item.startSalePrice }}万</span>
                <span v-else>--</span>
              </p>
              <img src="../../assets/img/zxzx.png" alt @click="On53" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      allHouse: []
    };
  },
  mounted() {
    this.OnCode();
  },
  methods: {
    On53() {
      window.open(
        "https://tb.53kf.com/code/client/9a12bb00652ff2c013fe004ae3947f845/1",
        "_blank"
      );
      this.stopBubbling(event);
    },
    stopBubbling(e) {
      e = window.event || e;
      if (e.stopPropagation) {
        e.stopPropagation(); //阻止事件 冒泡传播
      } else {
        e.cancelBubble = true; //ie兼容
      }
    },
    OnCode() {
      const that = this;
      this.instance
        .HouseList({
          page: 1,
          limit: 6
        })
        .then(res => {
          console.log(res);
          if (res.data.code == "0") {
            that.allHouse = res.data.data;
            that.allHouse.forEach(item => {
              item.img = item.imgUrl.split(",");
            });
          }
        })
        .catch(function(error) {});
    },
    onDetails(item) {
      this.$router.push({ path: "/details", query: { id: item } });
    },
    Onfollow(val, idx) {
      if (val.ynFollow == 0) {
        this.$message({
          message: "请先登录",
          type: "warning"
        });
      } else if (val == 1) {
        this.instance
          .cancelHouseFollow({
            id: val.id
          })
          .then(res => {
            if (res.data.code == "0") {
              this.OnCode();
            }
          })
          .catch(function(error) {});
      } else {
        this.instance
          .addHouseFollow({
            houseId: val.id
          })
          .then(res => {
            if (res.data.code == "0") {
              this.OnCode();
            }
          })
          .catch(function(error) {});
      }
      this.stopBubbling(event);
    }
  }
};
</script>
<style lang="less" scoped>
.recommend {
  width: 1200px;
  margin: 0 auto;
  padding-bottom: 60px;
  .housing {
    margin: 30px 0;
    height: 50px;
    background: #fff4f2;
    text-align: center;
    font-size: 14px;
    color: #f4633d;
    line-height: 50px;
  }
  .excellent {
    padding-bottom: 30px;
    border-bottom: 1px solid #e9e9e9;
    font-weight: bold;
    font-size: 22px;
  }
  .house_list {
    overflow: hidden;
    .list {
      cursor: pointer;
      float: left;
      width: 31.33%;
      margin-right: 20px;
      margin-top: 10px;
      .price {
        position: relative;
        .home_img {
          width: 380px;
          height: 214px;
          border-radius: 6px;
          margin-bottom: 35px;
        }
        .soon {
          position: absolute;
          top: 0;
          width: 89px;
          height: 31px;
          background: linear-gradient(0deg, #19aa6b, #3cd6a2, #3cd8a4);
          border-radius: 6px 0px 6px 0px;
          line-height: 31px;
          text-align: center;
          font-size: 14px;
          color: #fff;
        }
        .heart {
          position: absolute;
          right: 0;
          top: 0;
          cursor: pointer;
          // top: 20px;
        }
        .home {
          position: absolute;
          top: 180px;
          right: 20px;
          width: 46px;
          height: 20px;
          background: #f5643e;
          border-radius: 2px;
          text-align: center;
          line-height: 20px;
          color: #fff;
          font-size: 12px;
        }
        .time {
          position: absolute;
          top: 200px;
          left: 20%;
          width: 226px;
          height: 33px;
          background: #ffffff;
          box-shadow: 0px 3px 7px 0px rgba(0, 0, 0, 0.05);
          border-radius: 17px;
          line-height: 33px;
          text-align: center;
          font-size: 13px;
          color: #7d7b7b;
        }
      }
      .list_title {
        width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 16px;
        font-weight: bold;
        color: #333333;
        margin-bottom: 15px;
      }
      .hall {
        padding: 3px;
        margin-right: 5px;
        font-size: 12px;
        color: #ff6565;
        background: #fff3f3;
      }
      .centare {
        padding: 3px;
        margin-right: 5px;
        font-size: 12px;
        color: #ff9555;
        background: #fff5df;
      }
      .orientation {
        padding: 3px;
        margin-right: 5px;
        font-size: 12px;
        color: #17d1bb;
        background: #e7f9f7;
      }
      .price {
        margin: 13px 0px;
        color: #656967;
      }
      .startPrice {
        overflow: hidden;
        .start {
          float: left;
          span {
            color: #f4643e;
          }
        }
        img {
          float: right;
          width: 20px;
          height: 20px;
        }
      }
    }
  }
}
</style>
